package x.welleys.stu.idea.livetemp;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.*;
import java.util.concurrent.Callable;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

/**
 * Desc：
 * Author：suzhiwei
 * Time：2017/8/30
 * Version: 2.0
 */
public class Test {
    /* test plain start */
    //psf
    public static final String strval = "123";
    //psfi
    public static final int intval = 3;
    //psfs
    public static final String strval2 = "456";
    //St
    String strval3 = "3";

    public void testPlain() throws IOException {
        //thr
        throw new IOException();
    }
    /** test plain end **/

    /* test surround start */

    public void testSurround() throws IOException {
        //C
        Callable<Object> callable = new Callable<Object>() {
            public Object call() throws Exception {
                return null;
            }
        };

        //I
        for (Object o : new Object[2]) {

        }

        //RL jdk1.5
        ReadWriteLock readWriteLock = new ReentrantReadWriteLock();
        readWriteLock.readLock().lock();
        try {

        } finally {
            readWriteLock.readLock().unlock();
        }
        //WL
        readWriteLock.writeLock().lock();
        try {

        } finally {
            readWriteLock.writeLock().unlock();
        }


        //TR jdk1.7
        try (BufferedReader br = new BufferedReader(new FileReader("test.txt"))) {

        }

    }
    /* test surround end */

    //logger
    private static final Logger LOGGER = LoggerFactory.getLogger(Test.class);
    //main
    public static void main(String[] args){
        //logcontext
        LOGGER.info("main, " + "args = [" + args + "]");
    }
    
    public static void test(int iVal, String strIndex){
        LOGGER.info("test " + "iVal = [" + iVal + "], strIndex = [" + strIndex + "]");

        List<String> strlist = new ArrayList<String>();
        //fore
        for(String s : strlist){
            if(null != s){
                //syso
                System.out.println("x.welleys.stu.idea.livetemp.Test-test, s=" + s);
            }
        }
    }

    /**
    * x.welleys.stu.idea.livetemp.Test field comment
    */
    private String name;

    /**
     * not all iterator
     */
    public void testIterations(){
        //fori
        for (int i = 0; i < 5; i++) {

        }

        //itar
        String[] strings = new String[4];
        for (int i = 0; i < strings.length; i++) {
            String string = strings[i];

        }

        //itco
        List<Integer> integers = new ArrayList<Integer>();
        for (Iterator<Integer> iterator = integers.iterator(); iterator.hasNext(); ) {
            Integer next = iterator.next();

        }

        //iten
        Hashtable hashtable = new Hashtable();
        for (int i = 0; i < 10; i++) {
            hashtable.put(i,i);
        }
        Enumeration enums = hashtable.elements();

        while (enums.hasMoreElements()) {
            Object nextElement =  enums.nextElement();
            System.out.println("x.welleys.stu.idea.livetemp.Test-testIterations, nextElement=" + nextElement);
        }
    }

    /** test other start **/
    public static Test getInstance() {
        return new Test();
    }
    public void testOther(){
        String s = "adb";
        //ifn
        if (s == null) {
            System.out.println("x.welleys.stu.idea.livetemp.Test-testOther, s=" + s);
        }
        //inn
        if (s != null) {
            System.out.println("x.welleys.stu.idea.livetemp.Test-testOther, s=" + s);
        }
        
        //inst
        if (s instanceof String) {
            String s1 = (String) s;
            System.out.println("x.welleys.stu.idea.livetemp.Test-testOther, s1=" + s1);
        }
        //lazy
        if (s == null) {
            s = new String();
        }
        //lst
        Integer[] integers = new Integer[4];
        System.out.println("x.welleys.stu.idea.livetemp.Test-testOther, interger last=" + integers[integers.length - 1]);

        //mn
        int minVal = 21;
        minVal = Math.min(minVal,22);
        System.out.println("x.welleys.stu.idea.livetemp.Test-testOther, minVal=" + minVal);
        
        //mx
        int maxVal = 99;
        maxVal = Math.max(maxVal, 100);
        System.out.println("x.welleys.stu.idea.livetemp.Test-testOther, maxVal=" + maxVal);

        //toar
        List<String> strings = new ArrayList<String>();
        String[] strings1=strings.toArray(new String[strings.size()]);
        System.out.println("x.welleys.stu.idea.livetemp.Test-testOther, strings1=" + strings1);

    }
    /** test other end **/

    /** test output start **/
    public void testOutput(){
        //serr
        System.err.println("");

        //souf
        System.out.printf("");

        //sout
        System.out.println();

        //soutm
        System.out.println("x.welleys.stu.idea.livetemp.Test.testOutput");

        //soutp
        System.out.println("");

        //soutv
        System.out.println("LOGGER = " + LOGGER);
    }
    /** test output end **/

}
